<template>
  <el-dialog title="商品退货明细" :visible.sync="dialogVisible" append-to-body>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="creatTime" header-align="left" align="left" label="时间" width="180">
      </el-table-column>
      <el-table-column prop="shopName" header-align="left" align="left" label="名称" width="180">
      </el-table-column>
      <el-table-column prop="type" header-align="left" align="left" label="类型" width="130">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">售出</span>
          <span v-if="scope.row.type == 2">退货</span>
        </template>
      </el-table-column>
      <el-table-column prop="buyNumber" header-align="left" align="left" label="退货数量" width="80">
      </el-table-column>
      <el-table-column prop="shopPrice" header-align="left" align="left" label="单价" width="80">
        <template slot-scope="scope">
          ￥{{scope.row.shopPrice}}
        </template>
      </el-table-column>
      <el-table-column header-align="left" align="left" label="总价">
        <template slot-scope="scope">
          ￥{{scope.row.shopPrice * scope.row.buyNumber}}
        </template>
      </el-table-column>
      <el-table-column prop="userName" header-align="left" align="left" label="操作员" width="180">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        dataForm: {
          key: '',
          type: '',
          startTime: '',
          endTime: '',
        },
        dialogVisible: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {

    },
    activated() {
      this.getDataList()
    },
    methods: {
      init(type, startTime, endTime) {
        this.dialogVisible = true;
        this.dataForm.startTime = startTime;
        this.dataForm.endTime = endTime;
        this.dataForm.type = type;
        this.pageIndex = 1;
        this.$nextTick(() => {
          this.getDataList();
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomshoprecord/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            ...this.dataForm
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
    }
  }
</script>
